package org.rexsong.sample.petstore.services;

import org.rexsong.sample.petstore.exceptions.PetStoreException;
import org.rexsong.sample.petstore.models.Pet;
import org.rexsong.sample.petstore.repositories.PetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetServiceImp implements PetService{

    private PetRepository petRepository;

    @Autowired
    public PetServiceImp(PetRepository petRepository) {
        this.petRepository = petRepository;
    }

    @Override
    public long save(Pet pet) {
        petRepository.save(pet);
        return petRepository.count();
    }

    @Override
    public long saveAll(List<Pet> pets) {
        petRepository.saveAll(pets);
        return petRepository.count();
    }

    @Override
    public long deleteById(long id) {
        petRepository.deleteById(id);
        return petRepository.count();
    }

    @Override
    public List<Pet> findAll() throws PetStoreException {
        return petRepository.findAll();
    }

    @Override
    public List<Pet> findByType(String type) {
        return petRepository.findByType(type);
    }

    @Override
    public List<Pet> findByStatus(String status) {
        return petRepository.findByStatus(status);
    }
}
